package com.java.base.exercise.corejava;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @Author RenPu
 * @Date 2022/8/25 18:52
 * @Version 1.0
 * @Description:线程demo
 **/
public class ThreadDemo {

    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(10);

        List<Integer> list = Arrays.asList(1, 2, 3);
        List<String> results=list.stream().map(key-> CompletableFuture.supplyAsync(()->{
            try {
                Thread.sleep(1000L);
            }catch (Exception e){

            }
            return "结果"+key;
        },threadPool)).map(CompletableFuture::join).collect(Collectors.toList());

        threadPool.shutdown();

        //获取结果值；
        System.out.println(results);
    }
}
